package com.meaningful.design_pattern.chain_of_responsibility.validation;

public class LengthValidatorHandler implements ValidationHandler {

    private final int length;

    public LengthValidatorHandler(int length) {
        this.length = length;
    }

    @Override
    public void validate(Object value, ValidatorContext context) throws ValidatorException {
        if (value instanceof String strValue) {
            if (strValue.length() > length) {
                context.appendError("字段长度超长");
            }
        }
    }
}
